<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table {
            width: 500px;
            border-collapse: collapse;
            text-align: center;
        }

        /* 偶数 2n even */
        table tbody tr:nth-child(2n) {
            background: red;
        }

        /* 奇数 2n-1 2n+1 odd */
        table tbody tr:nth-child(odd) {
            background: blue;
        }

        /* -n+5 找到前五个 */
        table tbody tr:nth-child(-n+5) {
            color: orange;
        }

        /* n+5 找到第5个往后的所有 */
        table tbody tr:nth-child(n+5) {
            color: rebeccapurple;
        }
    </style>
</head>

<body>
    <!-- 实现隔行变色效果 -->
    <table border="1">
        <thead>
            <tr>
                <th>姓名</th>
                <th>班级</th>
                <th>年纪</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
            <tr>
                <td>刘**</td>
                <td>163班</td>
                <td>2019</td>
            </tr>
        </tbody>
    </table>
</body>

</html>